import Vue from 'vue'
import VueRouter from 'vue-router'
import CampusBinhai from '../views/CampusBinhai.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Binhai',
    component: CampusBinhai
  },
  {
    path: '/Chashan',
    name: 'Chashan',
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/CampusChashan.vue')
    }
  },
  {
    path: '/Yueqing',
    name: 'Yueqing',
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/CampusYueqing.vue')
    }
  },
  {
    path: '/StudentSystem',
    name: 'StudentSystem',
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/StudentSystem.vue')
    },
    beforeEnter: (to, from, next) => {
      // 判断是否已登录
      if (!localStorage.getItem("isLoggedIn")) {
        // 未登录，跳转到Login页面
        next("/login");
      } else {
        // 已登录，允许访问
        next();
      }
    }
  },
  {
    path: '/Login',
    name: 'Login',
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/Login.vue')
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
